from typing import Optional


# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next


def getListNode(*nums) -> Optional[ListNode]:
    head = ListNode(-1)
    cur = head
    for t in nums:
        cur.next = ListNode(t)
        cur = cur.next
    return head.next


def vistListNode(head: Optional[ListNode]):
    while head:
        endStr = '->'
        if not head.next:
            endStr = ''
        print(head.val, end=endStr)
        head = head.next
